home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7912 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: news.th-darmstadt.de!news
  2. From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: New operator
  5. Date: Wed, 14 Feb 1996 09:14:07 +0100
  6. Organization: Fachbereich Informatik, TH Darmstadt
  7. Message-ID: <312199CF.41C67EA6@intellektik.informatik.th-darmstadt.de>
  8. References: <1996Feb14.022723.6407@cronkite.res.utc.com>
  9. NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (X11; I; SunOS 4.1.3 sun4m)
  14.  
  15. Marco DeFreitas wrote:
  16. > If I use the explicit placement form of new to create an object from
  17. > some specified memory, can I delete it?
  18. > char     buf[100];
  19. > Object  *obj;
  20. >    obj = new (buf) Object;
  21. >    delete obj;
  22. > What actually happens?  I tried it on an SGI version of C++ and it does
  23. > not complain - but is this legal?  Is it really doing a delete of my buf?
  24. > Or is the delete being ignored.   Thanks in advance for any input.
  25.  
  26. 'delete' is the wrong choice. It would free memory that wasn't
  27. allocated via 'new'. Use a direct call of the dtor instead:
  28.  
  29.             obj->~Object();
  30.  
  31. This turns back the 'buf' into raw-memory.
  32.  
  33.     Enno
  34.